<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
    /**
    * @param {character[][]} matrix
    * @return {number}
    */
    var maximalSquare = function(ary) {
        var max=0;
        var len=ary.length;
        var row=0;
        if(len)
        row=ary[0].length;
        for(var i=0;i<len;i++)
        {
            if(ary[i][0]==1)
            max=1;
        }
        for(var i=0;i<row;i++)
        {
            if(ary[0][i]==1)
            max=1;
        }
        console.log(max);
        for(var i=1;i<ary.length;i++)
        {
            for(var j=1;j<ary[i].length;j++){
                if(ary[i][j]==1)
                {
                    ary[i][j]=Math.min(ary[i-1][j],ary[i-1][j-1],ary[i][j-1])+1;
                    max=Math.max(max,ary[i][j]);
                }
            }
        }
        // console.log(max);
        return max*max;
    };
    var a=[ [1,0,1,0,0],
            [1,0,1,1,1],
            [1,1,1,1,1],
            [1,0,1,1,0]];
    maximalSquare(a);
    </script>
</body>
</html>